﻿using System;
using System.IO;
using System.Windows.Media.Imaging;
using System.Xml.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.Xml;

namespace Telerik.Examples.WP
{
    /// <summary>
    /// 
    /// </summary>
    public class MovieViewModel
    {
        private string projects;
        private string tokenCounts;
        private string counts;
        private string audienceRating;
        private string cast;
        private string director;
        private string year;
        private string duration;
        private string base64Image;
        private BitmapImage bitmap;

        private bool durationFormatted;
        
        /// <summary>
        /// Initializes a new instance of the <see cref="MovieViewModel" /> class.
        /// </summary>
        public MovieViewModel()
        {
        }

        /// <summary>
        /// Gets the bitmap.
        /// </summary>
        /// <value>The bitmap.</value>
        [XmlIgnore]
        public BitmapImage Bitmap
        {
            get
            {
                if (this.bitmap == null && !string.IsNullOrEmpty(this.base64Image))
                {
                    byte[] imageBytes = System.Convert.FromBase64String(this.base64Image);
                    BitmapImage img = new BitmapImage();
                    img.SetSource(new MemoryStream(imageBytes));
                    this.bitmap = img;
                }
                return this.bitmap;
            }
        }

        /// <summary>
        /// Gets or sets the year.
        /// </summary>
        /// <value>The year.</value>
        public string Projects
        {
            get
            {
                return this.projects;
            }
            set
            {
                this.projects = value;
            }
        }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string TokenCounts
        {
            get
            {
                return this.tokenCounts;
            }
            set
            {
                this.tokenCounts = value;
            }
        }

        /// <summary>
        /// Gets or sets the rating.
        /// </summary>
        /// <value>The rating.</value>
        public string Counts
        {
            get
            {
                return this.counts;
            }
            set
            {
                this.counts = value;
            }
        }


        /// <summary>
        /// Gets or sets the base64 image.
        /// </summary>
        /// <value>The base64 image.</value>
        public string Base64Image
        {
            get
            {
                return this.base64Image;
            }
            set
            {
                this.base64Image = value;
            }
        }
    }
}
